<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="栏目名称" prop="columnName">
        <el-input
          v-model="queryParams.columnName"
          placeholder="请输入栏目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
	    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-sort"
          size="mini"
          @click="toggleExpandAll"
        >展开/折叠</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-if="refreshTable"
      v-loading="loading"
      :data="infoColumnList"
      row-key="columnId"
      :default-expand-all="isExpandAll"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <!-- <el-table-column label="上级id" prop="parentId" /> -->
      <el-table-column label="栏目名称" align="center" prop="columnName" />
      <el-table-column label="排序" align="center" prop="orderNum" />
      <el-table-column prop="state" label="状态" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_column_state" :value="scope.row.state"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button v-if="scope.row.isDetail == 'Y'"
            size="mini"
            type="text"
            icon="el-icon-message"
            @click="handleDetail(scope.row)"
            v-hasPermi="['business:infoColumn:remove']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { listInfoColumn } from "@/api/business/infoColumn";

export default {
  name: "IndexPrevate",
  dicts: ['tb_column_state', 'sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 栏目信息表格数据
      infoColumnList: [],
      // 栏目信息树选项
      infoColumnOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        columnName: null,
        state: null,
        isOpen: 'Y'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleDetail(row){
      this.$router.push({
        path: "/forum/columnDetail",
        query: { columnId: row.columnId },
      });
    },
    /** 查询栏目信息列表 */
    getList() {
      this.loading = true;
      listInfoColumn(this.queryParams).then(response => {
        this.infoColumnList = this.handleTree(response.data, "columnId", "parentId");
        this.loading = false;
      });
    },
    /** 转换栏目信息数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.columnId,
        label: node.columnName,
        children: node.children
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    }
  }
};
</script>
